package com.sktlab.bizconfmobile.model.manager;

import java.util.ArrayList;
import java.util.Hashtable;
import com.sktlab.bizconfmobile.model.Meeting;
import com.sktlab.bizconfmobile.util.CalendarUtil;
import com.sktlab.bizconfmobile.util.Util;

public class CalendarManager {
	
	public static final String TAG = "CalendarManager";
	
    private static ArrayList<Meeting> meetings = null;
	private Hashtable<String, ArrayList<Meeting>> dayToConfs;
	
	private CalendarManager() {
		
		dayToConfs = new Hashtable<String, ArrayList<Meeting>>();
		meetings = new ArrayList<Meeting>(); 

	}
	
	private static class InstanceHolder {

		private static CalendarManager instance = new CalendarManager();
	}
	
	public static CalendarManager getInstance() {

		return InstanceHolder.instance;
	}
	
	public boolean hasRecord(Long date) {
		
		String dateFomat = CalendarUtil.getFomatDateStr(date);
		
		//Util.BIZ_CONF_DEBUG(TAG, "date fomat str: " + dateFomat);
		return dayToConfs.containsKey(dateFomat);
	}
	
	public void addMeeting(Meeting newMeeting) {
	
		meetings.add(newMeeting);
		
		String key = newMeeting.getDate();
		
		if(dayToConfs.containsKey(key)) {
			
			Util.BIZ_CONF_DEBUG(TAG, "contains key: " + key);
			
			dayToConfs.get(key).add(newMeeting);
		}else {
			
			Util.BIZ_CONF_DEBUG(TAG, "add new key: " + key);
			ArrayList<Meeting> dateMeeting = new ArrayList<Meeting>();
			dateMeeting.add(newMeeting);
			
			dayToConfs.put(key, dateMeeting);
		}
	}
	
	public ArrayList<Meeting> getCellMeetings(String dateFomatStr) {
		
		ArrayList<Meeting> meetings = null;
		
		if (dayToConfs.containsKey(dateFomatStr)) {
			
			meetings = dayToConfs.get(dateFomatStr);
		}
		
		return meetings;
	}
	
	public Hashtable<String, ArrayList<Meeting>> getDayToConfs() {
		return dayToConfs;
	}

	public void setDayToConfs(Hashtable<String, ArrayList<Meeting>> dayToConfs) {
		this.dayToConfs = dayToConfs;
	}

	public  ArrayList<Meeting> getAllMeetings() {
		return meetings;
	}

	public  void setConfs(ArrayList<Meeting> confs) {
		CalendarManager.meetings = confs;
	}	
}
